#include <stdio.h>
#include <stdlib.h>

double crono()
	{
		struct timeval tv;
		gettimeofday(&tv,0);
		return tv.tv_sec + tv.tv_usec/1e6;
	}


int main(int argc, char **argv)
	{
		int size = atoi(argv[1]);
		int i,j,r;
		float **m1,**m2,**mr;
		double start,end;

		// crono chama a funcao que inicia contar o tempo
		start = crono();
		
		if( ((m1 = (float **)  malloc(sizeof(float*) * size))==NULL) || ((m2 = (float **) malloc(sizeof(float*) * size))==NULL) || ((mr = (float **) malloc(sizeof(float*) *size)) == NULL))
			{
				printf("Erro na alocação!");
				exit(1);
			}
		for(i=0;i<size;i++)
			{
				m1[i] = malloc(sizeof(float) * size);
				m2[i] = malloc(sizeof(float) * size);
				mr[i] = malloc(sizeof(float) * size);
			}


		for(i=0;i<size;i++)
			for(j=0;j<size;j++)
				m1[i][j] = i;
			
		for(i=0;i<size;i++)	
			for(r=0;r<size;r++)
				m2[i][j] = j;
			
		for(i=0;i<size;i++)	
			for(r=0;r<size;r++)
				mr[i][j] = 0;

		for(i=0;i<size;i++)
			for(j=0;j<size;j++)
				for(r=0;r<size;r++)
					mr[i][j] += m1[i][r] * m2[r][j];
				
/*		for(i=0;i<size;i++)
			{
				for(j=0;j<size;j++)
					printf("%f  ",mr[i][j]);
				printf("\n");
			}
*/	
		end = crono();

		printf("%f\n",end-start);
	return 0;
	}	
